package tools

import (
	"fmt"

	"github.com/jedib0t/go-pretty/v6/table"
	"github.com/jedib0t/go-pretty/v6/text"
)

func (t Command) Help2() {
	fmt.Println("=========yt v0.7===============")
	fmt.Println("yt help   输出帮助信息")
	fmt.Println("yt version  输出版本信息")
	fmt.Println("yt telnet  {ip} {port} 测试ip对应的port是否监听")
	fmt.Println("yt curl   {url} 测试url是否可以请求")
	fmt.Println("yt cat   {filepath} 查看文件内容")
	fmt.Println("yt grep   {key} {filepath} 查看文件包含key的行内容")
	fmt.Println("yt replace {oldStr} {newStr} {filepath} 指定文件下的oldStr替换为newStr")
	fmt.Println("yt tail  {show_line_num} {filepath} 类似linux的tail功能show_line_num查看最后几行，后面实时输出")
	fmt.Println("yt ps   {name} 查找进程pid")
	fmt.Println("yt kill   {pid} 杀死进程")
	fmt.Println("yt server {ip}  {port} 启动socket服务，client文件传输好自动关闭")
	fmt.Println("yt client  {ip} {port} {filepath} 把文件传输给server端")
	fmt.Println("yt unzip  {filepath} {targetDir} 解压文件到指定目录（支持zip/tar/tar.gz/tar.bz2）")
	fmt.Println("yt zip    {sourceDir} {targetFile} 压缩目录为指定格式（支持zip/tar/tar.gz/tar.bz2）")
	fmt.Println("===================================")
}

func (t Command) Help() {
	tw := table.NewWriter()
	//tw.SetStyle(table.StyleBox)
	tw.SetTitle("yt v0.7 命令帮助")
	tw.AppendHeader(table.Row{"命令格式", "功能描述"})

	tw.AppendRows([]table.Row{
		{"yt help", "输出帮助信息"},
		{"yt version", "输出版本信息"},
		{"yt telnet {ip} {port}", "测试端口监听状态"},
		{"yt curl {url}", "测试URL可达性"},
		{"yt cat {filepath}", "查看文件内容"},
		{"yt grep {key} {filepath}", "文件关键词搜索"},
		{"yt replace {old} {new} {file}", "文件内容替换"},
		{"yt tail {num} {filepath}", "实时监控文件尾部"},
		{"yt ps {name}", "进程PID查找"},
		{"yt kill {pid}", "终止指定进程"},
		{"yt server {ip} {port}", "启动Socket服务"},
		{"yt client {ip} {port} {file}", "文件传输客户端"},
		{"yt unzip {file} {dir}", "解压文件到指定目录,支持zip/tar.gz/tar.bz2"},
		{"yt zip {dir} {file}", "目录压缩打包,支持zip/tar.gz/tar.bz2"},
	})

	tw.SetColumnConfigs([]table.ColumnConfig{
		{Number: 1, WidthMax: 35, Align: text.AlignLeft},
		{Number: 2, WidthMax: 50, Align: text.AlignLeft},
	})

	fmt.Println(tw.Render())
}
